package com.njtoyo.taxi.admin.rest.controller.business.geo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.master.entity.City;
import com.njtoyo.taxi.admin.rest.presenter.business.geo.AllListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.city.CityCreateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.city.CityQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.city.CityUpdateWrapper;
import com.njtoyo.taxi.admin.service.business.geo.CityService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "城市管理", tags = "城市")
@RequestMapping("business/geo/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping()
    @ApiOperation(value = "全部城市列表", notes = "city_list")
    @PermissionScope(names = {"city_list"})
    RestResult<IPage<City>> getList(CityQueryWrapper wrapper) {
        return cityService.getList(wrapper);
    }

    @PostMapping()
    @ApiOperation(value = "新增城市", notes = "city_create")
    @PermissionScope(names = {"city_create"})
    RestResult create(@Valid @RequestBody CityCreateWrapper wrapper) {
        return cityService.create(wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改城市", notes = "权限：city_update")
    @PermissionScope(names = {"city_update"})
    RestResult<Boolean> update(@PathVariable Long id, @RequestBody CityUpdateWrapper wrapper) {
        return cityService.update(id, wrapper);
    }

    @GetMapping("/all")
    @ApiOperation(value = "全部地区", notes = "无接口权限校验")
    RestResult<List<AllListPresenter>> getAll(@ModelAttribute("admin") AdminUser adminUser) {
        return cityService.getAll(adminUser);
    }

}
